package org.nebuloop.photo.organizer.util;

import java.util.Calendar;

import com.mdimension.jchronic.Chronic;
import com.mdimension.jchronic.Options;
import com.mdimension.jchronic.utils.Span;

public class DateUtil {

  private DateUtil() {
  }

  public static boolean isDate(String str) {
    return parseDate(str) != null;
  }

  public static Calendar parseDateAsCalendar(String string) {
    Span time = parseDate(string);

    return time == null ? null : time.getEndCalendar();
  }

  public static Span parseDate(String string) {
    Span time = parseDate(string, new Options());
    if (time == null) {
      String s = string.replace(",", " ").replace("_", " at ");
      time = parseDate(s, new Options());
    }
    return time;
  }

  public static Span parseDate(String string, Options options) {
    options.setNow(Calendar.getInstance());
    options.setCompatibilityMode(true);
    return Chronic.parse(string, options);
  }
}
